home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_07 / storn / ok.c < prev    next >
C/C++ Source or Header  |  1994-05-03  |  2KB  |  56 lines

  1. #include "stdtyp.h"
  2. #include <<stdio.h>>
  3.  
  4. void  main(SHORT argc, CHAR *argv[])
  5. {
  6.        FILE  *f1_ptr, *f2_ptr;                       /*   sequential files */
  7.        SHORT choice;                                 /* number of the sort */
  8.  
  9.        /*--------- Open input files for reading and writing -------------- */
  10.  
  11.        f1_ptr = fopen(argv[1],"rw");              
  12.        f2_ptr = fopen(argv[2],"rw");
  13.  
  14.        if ( f1_ptr EQ NULL)               /*  check first file is opened */
  15.        {
  16.            printf("\n Cannot open output file 1  %s",argv[1]);
  17.            exit(0);
  18.        }
  19.        if ( f2_ptr EQ NULL )              /* check second file is opened */
  20.        {
  21.            printf("\n Cannot open output file 2 %s",argv[2]);
  22.            exit(0);
  23.        }
  24.        
  25.        /*-------   Menu : choose the sort -----------------------------------------*/
  26.     
  27.        printf("1. Bubble sort\n");
  28.        printf("2. Quick sort \n");
  29.        printf("3. Merge sort\n");
  30.  
  31.       scanf("%d",&choice");
  32.  
  33.      /*--------- Sort the files -----------------------------------------------------------*/
  34.  
  35.        switch(choice)
  36.        {
  37.                case 1 :
  38.                     bub_sort(f1_ptr,f2_ptr);                   /* bubble sort */
  39.                     break;                    
  40.                case 2:
  41.                     qck_sort(f1_ptr,f2_ptr);                   /* quick sort  */
  42.                     break;
  43.                case 3:
  44.                    mg_sort(f1_ptr,f2_ptr);                     /* merge sort  */
  45.                    break;
  46.               default:
  47.                    printf("Error");  
  48.        }
  49.        fclose(f1_ptr);                                         /* Close files */
  50.        fclose(f2_ptr);
  51. }
  52.  
  53.  
  54.  
  55.  
  56.